package com.hp.gxw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hp.gxw.entity.CostWorkOrderStatus;
import com.hp.gxw.mapper.CostWorkOrderStatusMapper;
import com.hp.gxw.service.ICostWorkOrderStatusService;
import com.hp.gxw.utils.DateUtil;
import com.hp.gxw.utils.HttpRequestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author huangping
 * @since 2024-02-21
 */
@Service
public class CostWorkOrderStatusServiceImpl extends ServiceImpl<CostWorkOrderStatusMapper, CostWorkOrderStatus> implements ICostWorkOrderStatusService {

    @Autowired
    private HttpRequestUtils httpRequestUtils;

    @Override
    @Transactional
    public void handlePull(String month) {
        //删除已存在的数据
        remove(new LambdaQueryWrapper<CostWorkOrderStatus>().eq(CostWorkOrderStatus::getMonth, month));
        List<CostWorkOrderStatus> list = httpRequestUtils.requestWorkOrderStatus(month+"-01", DateUtil.getLastDayOfMonthStr(month));
        if(list != null && list.size() > 0){
            saveBatch(list);
        }
    }
}
